﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Common.Utilities;
using Common.Utilities.Dispatcher;

namespace Workflows.Components.Reports
{
	/// <summary>
	/// 
	/// </summary>
	[Serializable]
	public class SetManipulationOutput:ResultBase
	{
		#region props
		private string _ResultFilePath;
		/// <summary></summary>
		public string ResultFilePath
		{
			get
			{
				return this._ResultFilePath;
			}
			set
			{
				this._ResultFilePath = value;
			}
		}
		#endregion

		#region ctor 
		/// <summary>
		/// 
		/// </summary>
		public SetManipulationOutput():base(Guid.Empty,Guid.Empty)
		{
			this._ResultFilePath = string.Empty;
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="componentID"></param>
		/// <param name="jobTicketID"></param>
		/// <param name="resultFilePath"></param>
		public SetManipulationOutput(Guid componentID, Guid jobTicketID, string resultFilePath) : base(componentID, jobTicketID)
		{
			this._ResultFilePath = resultFilePath;
		}
		#endregion

		#region Overrides of ResultBase

		/// <summary>
		/// 
		/// </summary>
		/// <param name="xDoc"></param>
		/// <param name="parentNode"></param>
		/// <returns></returns>
		public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
		{
			XmlNode xNode = XmlDataUtil.AddElement(ref xDoc, parentNode, "Output");
			XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "Type", this.GetType().FullName);
			XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "WorkerID", this.OwnerWorkerInstanceID.ToString());
			XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FinishTime", this.FinishTime.ToString());

			XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "ResultFilePath", this.ResultFilePath);

			return xNode;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="xNode"></param>
		/// <returns></returns>
		public override ResultBase Instantiate(XmlNode xNode)
		{
			if (xNode.Attributes.GetNamedItem("Type").Value == this.GetType().FullName)
			{
				SetManipulationOutput output = new SetManipulationOutput();
				output.OwnerWorkerInstanceID = new Guid(xNode.Attributes.GetNamedItem("WorkerID").Value);
				output.FinishTime = DateTime.Parse(xNode.Attributes.GetNamedItem("FinishTime").Value);

				output.ResultFilePath = xNode.Attributes.GetNamedItem("ResultFilePath").Value;

				return output;
			}
			else
			{
				throw new Exception("Unable to instantiate output: invalid type specified in xml node");
			}
		}

		#endregion
	}
}
